package com.xcl.controller;

import com.xcl.service.DebtServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName DebtController
 * @Description 欠款核销控制器
 * @Author: xiaochaolei
 * @date 2021/7/29 10:04
 * @Version 1. 0
 */
@Controller
public class DebtController {

    @Autowired
    DebtServiceInter debtServiceInter;

    /**
     * 分页查询以及多条件查询
     * @param page 页码数
     * @param limit 条目数
     * @param consignDate 日期
     * @param tms_name 业务员
     * @param forwardingUnit 欠款单位
     * @param sub_id 分站
     * @param verification 是否核销
     * @return map的集合类型
     */
    @GetMapping(value = "/DebtControllerGetALLDebt", produces = "application/json;charset=utf-8")
    @ResponseBody
    public Map<String,Object> getALLDebt(int page, int limit,String consignDate,String tms_name,String forwardingUnit,String sub_id,String verification){
        //定义一个map集合
        Map<String,Object> map = new HashMap<>();
        map.put("code","0");
        map.put("msg","0");
        map.put("count",debtServiceInter.getALLDebt(consignDate,tms_name,forwardingUnit,sub_id,verification).size());
        map.put("data",debtServiceInter.getALLDebtBylimit(page,limit,consignDate,tms_name,forwardingUnit,sub_id,verification));
        return map;
    }

    /**
     * 订单核销
     * @param id 财务id
     * @return 是否成功
     */
    @PostMapping(value = "/DebtControllerUpdateVerification", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String updateVerification(String id){
       if ( debtServiceInter.updateVerification(id)>0){
           return "成功";
       }
        return "失败";
    }

    /**
     * 订单作废
     * @param id 财务id
     * @return 是否成功
     */
    @PostMapping(value = "/DebtControllerUpdateZuoFei", produces = "application/text;charset=utf-8")
    @ResponseBody
    public String updateZuoFei(String id){
        if ( debtServiceInter.updateZuoFei(id)>0){
            return "成功";
        }
        return "失败";
    }

}
